/** 
 * Forward declaration of guess API.
 * @param  num   your guess
 * @return 	     -1 if num is lower than the guess number
 *			      1 if num is higher than the guess number
 *               otherwise return 0
 * int guess(int num);
 */

int guess(int num);

class Solution {
public:
    int guessNumber(int n) {
        int left = 0;
        int right = n;
        int mid = left + (right - left) / 2;
        while (left <= right) {
            if (guess(mid) == 1) {
                right = mid;
            } else if (guess(mid) == -1) {
                left = mid;
            } else if (!guess(mid)) {
                return mid;
            }
        }
        return -1;
    }
};